package com.entity;

import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Type;

import javax.persistence.*;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;

import java.math.BigDecimal;
import java.util.List;


/**
 * The persistent class for the DRAWWORD database table.
 * 
 */
@Entity
@NamedQuery(name="Word.findAll", query="SELECT d FROM Word d")
public class Word implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(name="DRAWWORD_WORDNO_GENERATOR", sequenceName="SEQ",initialValue=1,allocationSize=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="DRAWWORD_WORDNO_GENERATOR")
	private Long wordno;

	private Boolean isuse;

	private String wname;
	
	private Boolean isshow;
	
	@OneToMany(mappedBy = "word",fetch=FetchType.EAGER)
//	@JSONField(serializeUsing = WordselSerializer.class)
	private List<Wordsel> wordsels;
	
	@OneToMany(mappedBy = "word"/*  */)
	@JSONField(serialize=false)
	private List<Cusword> cuswords;

	//bi-directional many-to-one association to Drawtypeword
	@ManyToOne
	@JoinColumn(name="TYPENO")
	private Drawtype drawtype;
	
	@ManyToOne
	@JoinColumn(name="WTNO")
	private Wordtype wordtype;
	
	@ManyToOne
	@JoinColumn(name="TEXTNO")
	private Texttype texttype;

	public Word() {
	}

	public Long getWordno() {
		return this.wordno;
	}

	public void setWordno(Long wordno) {
		this.wordno = wordno;
	}

	public Boolean getIsuse() {
		return this.isuse;
	}

	public void setIsuse(Boolean isuse) {
		this.isuse = isuse;
	}

	public String getWname() {
		return this.wname;
	}

	public void setWname(String wname) {
		this.wname = wname;
	}
	
	public Boolean getIsshow() {
		return isshow;
	}

	public void setIsshow(Boolean isshow) {
		this.isshow = isshow;
	}

	public Drawtype getDrawtype() {
		return drawtype;
	}

	public void setDrawtype(Drawtype drawtype) {
		this.drawtype = drawtype;
	}
	
	public List<Wordsel> getWordsels() {
		return wordsels;
	}

	public void setWordsels(List<Wordsel> wordsels) {
		this.wordsels = wordsels;
	}

	public Wordsel addWordsel(Wordsel wordsel) {
		getWordsels().add(wordsel);
		wordsel.setWord(this);
		
		return wordsel;
	}
	
	public Wordsel removeWordsel(Wordsel wordsel) {
		getWordsels().remove(wordsel);
		wordsel.setWord(null);
		
		return wordsel;
	}

	public Texttype getTexttype() {
		return texttype;
	}

	public void setTexttype(Texttype texttype) {
		this.texttype = texttype;
	}

	public List<Cusword> getCuswords() {
		return cuswords;
	}

	public void setDrawwords(List<Cusword> cuswords) {
		this.cuswords = cuswords;
	}
	
	public Cusword addDrawword(Cusword cusword) {
		getCuswords().add(cusword);
		cusword.setWord(this);
		
		return cusword;
	}
	
	public Cusword removeDrawword(Cusword cusword) {
		getCuswords().remove(cusword);
		cusword.setWord(null);
		
		return cusword;
	}
	
//	public static class WordselSerializer implements ObjectSerializer {
//        @Override
//        public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,int features) throws IOException {
//        	if(object==null) {
//        		serializer.write(object);
//        	}else {
//        		for(Wordsel wordsel:(List<Wordsel>)object) {
//            		wordsel = (Wordsel)object;
//    	        	String wordselStr = "selvalno=" + wordsel.getSelvalno() + ", isdefault=" + wordsel.getIsdefault()
//    	        	+ ", wselisuse=" + wordsel.getWselisuse() + ", selvalname="+ wordsel.getSelvalname();
//    	            serializer.write(wordsel);
//            	}
//        	}
//        	Wordsel wordsel = (Wordsel)object;
//        	if(wordsel!=null) {
//	        	String wordselStr = "selvalno=" + wordsel.getSelvalno() + ", isdefault=" + wordsel.getIsdefault()
//	        	+ ", wselisuse=" + wordsel.getWselisuse() + ", selvalname="+ wordsel.getSelvalname();
//	            serializer.write(wordsel);
//        	}else {
//        		serializer.write(null);
//        	}
//        }
//
//    }
	
	@Override
	public String toString() {
		return "Word [wordno=" + wordno + ", isuse=" + isuse + ", wname=" + wname + ", drawtype=" + drawtype +", wordsels="+ wordsels
				+ ", texttype=" + texttype + "]";
	}
	
	
}